package com.luo.service.impl;

import com.luo.mapper.UserMapper;
import com.luo.pojo.Results;
import com.luo.pojo.User;
import com.luo.service.UserService;
import com.luo.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    @Autowired
    private UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }



    @Override
    public Results login(User user) {
        User user1 = userMapper.login(user);
        if (user1 != null) {
            if (user1.getState()==1){
            Map<String, Object> claims = new HashMap<>();
            claims.put("userId", user1.getUserId());
            return Results.success(JwtUtils.getToken(claims));
            }else{
                return Results.error("账号已被封禁");
            }
        }else {
            return Results.error("用户名或密码");
        }
    }
}
